Imports capaLogica
Public Class VentanaAsistencia
    Private codigoGrupo As Integer
    Private gestor As GestorEquipo
    Private gestorAsistencia As GestorAsistencia

    Public Sub New(ByVal idGrupo As Integer)
        Me.InitializeComponent()
        Me.codigoGrupo = idGrupo
        Me.gestor = New GestorEquipo()
        Me.gestorAsistencia = New GestorAsistencia()
    End Sub

    Private Sub VentanaAsistencia_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.CargarEstudiantes()

    End Sub

    Private Sub CargarEstudiantes()

        Dim estudiantes As DataTable = gestor.LevantarEstudiantes(codigoGrupo)

        DataGridViewRegistrarAsistencia.DataSource = estudiantes
        With Me.DataGridViewRegistrarAsistencia.Columns.Item("idEstudiante")
            .HeaderText = "Carnet"
            .DisplayIndex = 1
            .Name = "idEstudiante"
        End With

        With Me.DataGridViewRegistrarAsistencia.Columns.Item("nombre")
            .HeaderText = "Nombre"
            .DisplayIndex = 2
        End With

        With Me.DataGridViewRegistrarAsistencia.Columns.Item("apellido1")
            .HeaderText = "Primer Apellido"
            .DisplayIndex = 3
        End With

        With Me.DataGridViewRegistrarAsistencia.Columns.Item("apellido2")
            .HeaderText = "Segundo Apellido"
            .DisplayIndex = 4
        End With

        With Me.DataGridViewRegistrarAsistencia.Columns.Item("correoElectronico")
            .Visible = False
        End With

        Dim cbSelCol As New DataGridViewCheckBoxColumn
        With cbSelCol
            .HeaderText = "Asistencia"
            .Name = "asistencia"
        End With
        DataGridViewRegistrarAsistencia.Columns.Insert(5, cbSelCol)
        For Each row As DataGridViewRow In DataGridViewRegistrarAsistencia.Rows
            row.Cells("asistencia").Value = True
        Next
    End Sub

    Private Sub btnAceptar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAceptar.Click
        Dim dat As New Date
        Dim idEstudiante As String
        dat = MonthCalendar1.SelectionRange.Start
        For Each row As DataGridViewRow In DataGridViewRegistrarAsistencia.Rows
            If row.Cells("asistencia").Value = False Then
                idEstudiante = row.Cells("idEstudiante").Value
                gestorAsistencia.registrarAusencia(codigoGrupo, idEstudiante, dat)
            End If

        Next
        Me.Dispose()
    End Sub

    Private Sub btnCancelar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancelar.Click
        Me.Dispose()
    End Sub
End Class